package WizardTD.board;

import WizardTD.App;
import WizardTD.enums.ButtonEnum;
import lombok.Data;
import processing.core.PApplet;

import java.util.function.Function;

@Data
public class FuncButton {

    float rectWidth = App.CELLSIZE * 1.5f;
    float rectHeight = App.CELLSIZE * 1.5f;
    private float rectX;
    private float rectY;
    private ButtonEnum buttonEnum;
    private Runnable doWork;

    public FuncButton() {}

    public FuncButton(float rectX, float rectY, ButtonEnum buttonEnum) {
        this.buttonEnum = buttonEnum;
        this.rectX = rectX;
        this.rectY = rectY;
    }

    public void draw(PApplet pApplet) {
        if (App.board.getChoiceButtons().contains(this.buttonEnum)) {
            pApplet.fill(255,255,0,100);
        } else {
            pApplet.noFill();
        }
        pApplet.rect(rectX, rectY, rectWidth, rectHeight);
        pApplet.fill(0);
        float textX = rectX + 5;
        float textY = rectY + rectHeight / 2 + 6;
        pApplet.textSize(24);
        pApplet.text(buttonEnum.getType(), textX, textY);
        pApplet.textSize(12);
        pApplet.text(buttonEnum.getMessage(), textX + App.CELLSIZE * 1.6f, textY - 6);
    }

    public void click() {
        if (App.board.getChoiceButtons().contains(buttonEnum)) {
            App.board.getChoiceButtons().remove(buttonEnum);
        } else {
            App.board.getChoiceButtons().add(buttonEnum);
        }
        if (doWork != null) doWork.run();
    }
}
